namespace DeepMixWorkflow
{
    public static class TagParser
    {
        private const string DeepMixPrefix = "[DM]";
        private const string OnAirPrefix = "[OnAir]";
        private const string SelectedPrefix = "[Selected]";
        private const string ErrorPrefix = "[Error]";

        public static DeepMixMode GetDeepMixMode(this string tag, out string uri)
        {
            if (tag != null)
                if (tag.StartsWith(DeepMixPrefix))
                {
                    tag = tag.Substring(4);
                    if (tag.StartsWith(OnAirPrefix))
                    {
                        uri = null;
                        return DeepMixMode.OnAir;
                    }
                    if (tag.StartsWith(SelectedPrefix))
                    {
                        tag = tag.Substring(SelectedPrefix.Length);
                        uri = tag;
                        return DeepMixMode.Selected;
                    }
                    if (tag.StartsWith(ErrorPrefix))
                    {
                        uri = null;
                        return DeepMixMode.Error;
                    }
                }
            uri = null;
            return DeepMixMode.Unknown;
        }

        public static string CreateOnAir()
        {
            return DeepMixPrefix + OnAirPrefix;
        }

        public static string CreateError()
        {
            return DeepMixPrefix + ErrorPrefix;
        }

        public static string CreateSelected(string trackUri)
        {
            return DeepMixPrefix + SelectedPrefix + trackUri;
        }
    }
}